package com.rh.bmw4s.utills;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.flyco.dialog.listener.OnBtnClickL;
import com.flyco.dialog.widget.NormalDialog;


/**
 * 监听网络状态广播
 */
public class NetWorkStateReceiver extends BroadcastReceiver {

    private boolean isHave = false;//是否有弹出框

    @Override
    public void onReceive(final Context context, Intent intent) {

        if (NetworkUtils.isConnected()) {
//            if (NetworkUtils.getWifiEnabled()) {
//                ToastUtils.toastForShort(context, "Wifi已连接");
//            } else if (NetworkUtils.getDataEnabled()) {
//                ToastUtils.toastForShort(context, "数据网络已连接");
//            }
        } else if (!isHave && !NetworkUtils.isConnected()) {
            isHave = true;
            final NormalDialog dialog = DialogUtils.getDialogMiddle(context, "提示", "网络已断开\n是否去设置网络?");
            dialog.btnText("退出", "去设置");
            dialog.show();
            dialog.setOnBtnClickL(new OnBtnClickL() {
                @Override
                public void onBtnClick() {
                    dialog.dismiss();
                    if (isHave) {
                        isHave = false;
                    }
                    ActivityCollector.getInstances().appExit(context);
                }
            }, new OnBtnClickL() {
                @Override
                public void onBtnClick() {
                    dialog.dismiss();
                    if (isHave) {
                        isHave = false;
                    }
                    NetworkUtils.openWirelessSettings();
                }
            });
        }
    }
}
